package com.yanqu.road.entity.activity.evefeast.config;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_s_activity_evefeast_buff")
public class EveFeastBuffConfig extends DataObject {
    @FieldTypeAnnotation(select = true, orderASC = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "祝酒词id", isIndex = true)
    private int greetingId;
    @FieldTypeAnnotation(desc = "名称")
    private String name;
    @FieldTypeAnnotation(desc = "描述")
    private String desc;
    @FieldTypeAnnotation(desc = "品质")
    private int quality;
    @FieldTypeAnnotation(desc = "权重")
    private String weight;
    @FieldTypeAnnotation(desc = "权重变化")
    private String weightChange;
    @FieldTypeAnnotation(desc = "技能参数")
    private String skill;
    @FieldTypeAnnotation(desc = "图标")
    private String icon;
    @FieldTypeAnnotation(desc = "按钮信息")
    private String buttonInfo;
    private List<Integer> weightParams = new ArrayList<>();

    private List<EveFeastBuffInfo> buffInfoList = new ArrayList<>();

    private Property weightChangeProperty = new Property();

    public EveFeastBuffConfig(int activityId, int greetingId) {
        this.activityId = activityId;
        this.greetingId = greetingId;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getGreetingId() {
        return greetingId;
    }

    public void setGreetingId(int greetingId) {
        this.greetingId = greetingId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getQuality() {
        return quality;
    }

    public void setQuality(int quality) {
        this.quality = quality;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
        if (!StringUtils.isNullOrEmpty(weight)) {
            setWeightParams(StringUtils.stringToIntegerList(weight, "\\|"));
        }
    }

    public String getWeightChange() {
        return weightChange;
    }

    public void setWeightChange(String weightChange) {
        this.weightChange = weightChange;
        if (!StringUtils.isNullOrEmpty(weightChange) && !weightChange.equals("0")) {
            this.weightChangeProperty = PropertyHelper.parseStringToProperty(weightChange, "\\|");
        }
    }

    public String getSkill() {
        return skill;
    }

    public void setSkill(String skill) {
        this.skill = skill;

        List<EveFeastBuffInfo> tempList = new ArrayList<>();
        if (!StringUtils.isNullOrEmpty(skill)) {
            String[] split = skill.split("@");
            for (String attr : split) {
                String[] split1 = attr.split("=");
                int buffType = Integer.valueOf(split1[0]);
                EveFeastBuffInfo eveFeastBuffInfo = new EveFeastBuffInfo(this.greetingId, buffType, split1[1]);
                tempList.add(eveFeastBuffInfo);
            }
        }
        setBuffInfoList(tempList);

    }

    public List<Integer> getWeightParams() {
        return weightParams;
    }

    public void setWeightParams(List<Integer> weightParams) {
        this.weightParams = weightParams;
    }

    public int getWeightByMission(int mission) {
        if (mission < 0 || mission >= weightParams.size()) {
            return 0;
        }

        return weightParams.get(mission);
    }

    public List<EveFeastBuffInfo> getBuffInfoList() {
        return buffInfoList;
    }

    public void setBuffInfoList(List<EveFeastBuffInfo> buffInfoList) {
        this.buffInfoList = buffInfoList;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Property getWeightChangeProperty() {
        return weightChangeProperty;
    }

    public void setWeightChangeProperty(Property weightChangeProperty) {
        this.weightChangeProperty = weightChangeProperty;
    }

    public String getButtonInfo() {
        return buttonInfo;
    }

    public void setButtonInfo(String buttonInfo) {
        this.buttonInfo = buttonInfo;
    }
}
